package com.ftt.product.controller;


import com.ftt.Util;
import com.ftt.product.model.ShoppingCar;
import com.ftt.product.service.ProductService;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/getCar.do")
public class ShoppingCarInfoServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取session对象并且拿session对象中的会员编号
        Object cId = req.getSession().getAttribute("customerId");
        //如果用户编号为空
        //改错2：逻辑判断错误
        if (cId == null) {
            //跳转到登入页面
            req.getRequestDispatcher("登录.jsp").forward(req, resp);
            return;
        }
        //将会员编号转为字符串类型
        String customerId = cId.toString();
        ProductService productService = new ProductService();
       List<ShoppingCar> list= productService.getShoppingCarInfo(customerId);
        Util.writerData(resp, list);
    }
}
